const express = require("express");
const {
  createWarehouse,
  getAllWarehouses,
  getWarehouseById,
  updateWarehouse,
  deleteWarehouse,
  getNearbyWarehouses,
  getWarehouseInventory,
} = require("../controllers/warehouseController");

const { authMiddleware, hasPermission } = require("../middleware/authMiddleware");

const router = express.Router();

// CREATE Warehouse
router.post(
  "/warehouses",
  authMiddleware,
  hasPermission("Warehouses", "Add"),
  createWarehouse
);

// GET All Warehouses
router.get(
  "/warehouses",
  authMiddleware,
  hasPermission("Warehouses", "View"),
  getAllWarehouses
);

// GET Nearby Warehouses
router.get(
  "/warehouses/near",
  authMiddleware,
  hasPermission("Warehouses", "View"),
  getNearbyWarehouses
);

// GET Single Warehouse
router.get(
  "/warehouses/:id",
  authMiddleware,
  hasPermission("Warehouses", "View"),
  getWarehouseById
);

router.get(
  "/warehouses/:id/inventory",
  authMiddleware,
  hasPermission("Warehouses", "View"),
  getWarehouseInventory
);

// UPDATE Warehouse
router.put(
  "/warehouses/:id",
  authMiddleware,
  hasPermission("Warehouses", "Edit"),
  updateWarehouse
);

// DELETE Warehouse
router.delete(
  "/warehouses/:id",
  authMiddleware,
  hasPermission("Warehouses", "Delete"),
  deleteWarehouse
);

module.exports = router;
